<?php

namespace app\api\controller;

use app\common\controller\Api;

/**
 * 首页接口
 */
class Project extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    public function get_list(){
        $categoryId = $this->request->get('category_id');
        $list = \app\api\model\Project::where('status',1)
            ->where(function ($q) use ($categoryId){
                if($categoryId){
                    $q->where('category_id',$categoryId);
                }
            })
            ->order('weigh','desc')
            ->field('id,cover,title_es,title_en')
            ->select();
        foreach ($list as &$value){
            $value['cover']=$value['cover']?$this->request->domain().$value['cover']:'';
        }
        $res = ['list' => $list];
        $this->success('成功',$res);
    }
    public function detail(){
        $newsId = $this->request->get('id');
        $res = \app\api\model\Project::where('status',1)->where('id',$newsId)->field('images,title_es,title_en')->find();
        if(!$res){
            $this->error('新闻不存在');
        }
        $res['images'] = explode(',',$res['images']);
        $images = [];
        foreach ($res['images'] as $v){
            $images[] = $this->request->domain().$v;
        }
        $res['images'] = $images;
        $this->success('成功',$res);
    }
}
